from bs4  import BeautifulSoup 
from bs4.element import *

file_path = '../data/index.html'
with open(file_path) as fr:
    demo = fr.read()

#解析demo的解释器
soup = BeautifulSoup(demo,'html.parser')

st = [[soup,0]]
# cur_st = 
while True:
    if len(st) != 0:
        cur_st = st.pop(-1)
    cur_ct = cur_st[0].contents 
    if len(cur_ct)-1 < cur_st[1]:
        if len(st) == 0:
            break
        continue
    for ei, et in enumerate(cur_ct[cur_st[1]:]):
        if isinstance(et, Tag):
            st.append([cur_st[0],1+ei+cur_st[1]])
            st.append([et,0])
            break 
        else:
            print(type(et), et)
    if len(st) == 0:
        break


# print(soup.a.next_sibling)
# print('-------------------')
# print(soup.a.next_sibling.next_sibling)
# print('-------------------')
# print(soup.a.previous_sibling)
# print('-------------------')
# print(soup.a.parent) 

